package controlador.ventas;

import controlador.ServletHelper;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import persistencia.BoletaDetalleComposite;

/**
 *
 * @author Felipe
 */
@WebServlet(name = "NuevaVenta", urlPatterns = {"/NuevaVenta"})
public class NuevaVenta extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        boolean condi = ServletHelper.validarUsu(request, response);
        if (condi) {
            HttpSession session = request.getSession();
            session.removeAttribute("Mensaje");
            if (session.getAttribute("CAJA") == null) {
                session.setAttribute("Mensaje", "Debe Crear La Caja Primero");
                request.getRequestDispatcher("/index.jsp").forward(request, response);

            } else {
                request.removeAttribute("Mensaje");
                BoletaDetalleComposite bdc = new BoletaDetalleComposite();
                session.setAttribute("BOLETA_DETALLE", bdc);
                request.getRequestDispatcher("/Ventas/VentaProductos.jsp").forward(request, response);
            }
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
